﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcProject.Models;
using Webdiyer.WebControls.Mvc;

namespace MvcProject.Controllers
{
    public class RatedInfoController : Controller
    {
        private BaseModels db = new BaseModels();
        //
        // GET: /RatedInfo/

        public ActionResult Index(int? page, string RatedCode, string RatedName, string RatedType)
        {
            PagedList<RatedInfo> ra = db.GetRatedInfos(RatedCode, RatedName, RatedType).ToPagedList(page ?? 1, 30);
            return View(ra);
        }

        //
        // GET: /RatedInfo/Details/5

        public ActionResult Details(int id)
        {
            RatedInfo ra = db.GetRatedInfo(id);
            return View(ra);
        }

        //
        // GET: /RatedInfo/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /RatedInfo/Create

        [HttpPost]
        public ActionResult Create(RatedInfo ra)
        {
            if (ModelState.IsValid)
                try
                {
                    UpdateModel(ra);
                    ra.CreateDate = System.DateTime.Now;
                    ra.CreateUserName = "ywx";
                    
                    db.Add(ra);
                    db.Save();
                    return RedirectToAction("Details", new { id = ra.RatedId });
                    
                }
                catch (Exception e)
                {
                    return View(ra);
                }
            return View(ra);
        }
        
        //
        // GET: /RatedInfo/Edit/5
 
        public ActionResult Edit(int id)
        {
            RatedInfo ra = db.GetRatedInfo(id);
            return View(ra);
        }

        //
        // POST: /RatedInfo/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            RatedInfo ra = db.GetRatedInfo(id);
            UpdateModel(ra);
            ra.CreateDate = System.DateTime.Now;
            ra.CreateUserName = "ywx";
            db.Save();
            return RedirectToAction("Details", new { id = ra.RatedId  });
        }

        //
        // GET: /RatedInfo/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /RatedInfo/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
